package role_api

import (
	"context"

	"github.com/gogf/gf/v2/util/gconv"

	v1 "gf-xb-api/api/role_api/v1"
	"gf-xb-api/internal/model/dto"
	"gf-xb-api/internal/service"
	"gf-xb-api/utility/xpointer"
)

func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
	var bTrue = xpointer.GetPointer(true)
	var bFalse = xpointer.GetPointer(false)

	var in *dto.CreateRoleApiInput
	if err = gconv.Struct(req, &in); err != nil {
		return (*v1.CreateRes)(bFalse), err
	}

	err = service.RoleApi().Create(ctx, in)
	if err != nil {
		return (*v1.CreateRes)(bFalse), err
	}

	return (*v1.CreateRes)(bTrue), nil
}
